package com.atwy.order.service.Impl;

import com.atwy.common.RespBean;
import com.atwy.order.feign.AccountFeign;
import com.atwy.order.mapper.OrderMapper;
import com.atwy.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    AccountFeign accountFeign;

    @Autowired
    OrderMapper orderMapper;

    @Override
    public boolean addOrder(String userId, String commodityCode, int count) {
        int money = count * 100;
        RespBean accountResp = accountFeign.account(userId, money);
        int i = orderMapper.createOrder(userId, commodityCode, count, money);

        return i == 1 && accountResp.getStatus().intValue() == 200;
    }
}
